define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'service/user/index' + location.search,
                    multi_url: 'service/user/multi',
                    import_url: 'service/user/import',
                    table: 'service_user_info',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'user.nickname', title: __('Nickname'),operate: false},
                        {field: 'user.avatar', title: __('Avatar'),events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'mobile', title: __('Mobile')},
                        {field: 'is_skill', title: __('Is_skill'), searchList: {"0":__('Is_skill 0'),"1":__('Is_skill 1')}, formatter: Table.api.formatter.normal},
                        {field: 'is_shop', title: __('Is_shop'), searchList: {"0":__('Is_shop 0'),"1":__('Is_shop 1')}, formatter: Table.api.formatter.normal},
                        // {field: 'unionid', title: __('Unionid'), operate: 'LIKE'},
                        // {field: 'user_openid', title: __('User_openid'), operate: 'LIKE'},
                        // {field: 'skill_openid', title: __('Skill_openid'), operate: 'LIKE'},
                        // {field: 'shop_openid', title: __('Shop_openid'), operate: 'LIKE'},
                        // {field: 'alipay_name', title: __('Alipay_name')},
                        // {field: 'alipay_account', title: __('Alipay_account'), operate: 'LIKE'},
                        // {field: 'bank_name', title: __('Bank_name'), operate: 'LIKE'},
                        // {field: 'bank_user', title: __('Bank_user')},
                        // {field: 'bank_card', title: __('Bank_card')},
                        {field: 'user.usermoney', title: __('Usermoney'),operate: false},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'shop_money', title: __('Shop_money'), operate:'BETWEEN'},
                        {field: 'shop_user_money', title: __('Shop_user_money'), operate:'BETWEEN'},
                        {field: 'is_plus', title: __('Is_plus'), searchList: {"0":__('Is_plus 0'),"1":__('Is_plus 1')}, formatter: Table.api.formatter.normal},

                        {field: 'discount', title: __('Discount')},
                        {field: 'plusname', title: __('Plusname'), operate: 'LIKE'},
                        {field: 'plustime', title: __('Plustime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'money',
                                    text: __('充值'),
                                    title: __('充值'),
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    
                                    url: function(row){
                                        return 'service/money/usermoneylog/deduct?user_id='+row.user_id;
                                    },
                                },
                                {
                                    name: 'list',
                                    text: __('余额明细'),
                                    title: __('余额明细'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-list-o',
                                    url: function(row){
                                        return 'service/money/usermoneylog/index?user_id='+row.user_id;
                                    },
                                },
                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
